package com.init.engineering.service.impl;

import com.init.engineering.dao.TaskplanDao;
import com.init.engineering.pages.PageResult;
import com.init.engineering.pages.QueryPageBean;
import com.init.engineering.pojo.Taskplan;
import com.init.engineering.service.TaskplanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class TaskplanServiceImpl implements TaskplanService {
    @Autowired(required = false)
    private TaskplanDao taskplanDao;

    @Override
    public List<Taskplan> findTaskplans() {
        List<Taskplan> taskplans = taskplanDao.findTaskplans();
        return taskplans;
    }

    @Override
    public PageResult findTaskplanByPage(QueryPageBean queryPageBean) {
        Integer begin = (queryPageBean.getCurrentPage() - 1) * queryPageBean.getPageSize();
        queryPageBean.setCurrentPage(begin);
        //查询当前页的数据集合
        List<Taskplan> taskplans = taskplanDao.findTaskplansByPage(queryPageBean);
        //获取分页查询的条件
        String queryString = queryPageBean.getQueryString();
        //获取分页查询按条件查询的总条数
        long totalCount = taskplanDao.selectTotalCount(queryString);

        //将数据封装到PageResult内
        PageResult pageResult = new PageResult();
        pageResult.setTotal(totalCount);
        pageResult.setRows(taskplans);
        return pageResult;
    }

    @Override
    public int saveTaskplan(Taskplan taskplan) {
        int rows = taskplanDao.saveTaskplan(taskplan);
        return rows;
    }

    @Override
    public int deleteTaskplan(String tid) {
        int rows = taskplanDao.updateTaskplanStatus(tid);
        return rows;
    }

    @Override
    public Taskplan findTaskplanByTid(String tid) {
        Taskplan taskplan = taskplanDao.findTaskplanByTid(tid);
        return taskplan;
    }

    @Override
    public int updateTaskplan(Taskplan taskplan) {
        int rows = taskplanDao.updateTaskplan(taskplan);
        return rows;
    }

    @Override
    public List<Taskplan> findTaskplansByBid(String bid) {
        List<Taskplan> taskplans = taskplanDao.findTaskplanByBid(bid);
        return taskplans;
    }
}
